
//加载方法
$(function (){
    $.ajax({
        url: "/DHMProceduring/queryByCheckTag01",
        type:"get",
        success:function (data){
            $("#zhixing").html(data);
        }
    })
    $.ajax({
        url: "/DHMProceduring/queryManufactureCountBy12",
        type:"get",
        success:function (data){
            $("#wancheng").html(data);
        }
    })

    //模糊查询的方法，生成表格
    $("#sccxTable").bootstrapTable({
        method:"get",
        contentType:"application/json;charset=utf-8",
        url: "/DHMProceduring/findAllMManufactureByCheckTag1",
        striped: true,
        pageNumber:1,
        pagination:true,
        sidePagination:"server",//设置服务端分页还是客户端分页
        pageSize:5,//页大小
        pageList:[3,5,9],//每页显示的条数
        queryParams:function (params) {
            return {
                pageNum: (params.offset / params.limit) + 1,
                pageSize:params.limit,
                manufactureId:$("#manufacture_id").val(),
            }
        },
        columns:[
            {title:'派工单编号',field:'manufactureId',align:'center'},
            {title:'产品编号',field:'productId',align:'center'},
            {title:'产品名称',field:'productName',align:'center'},
            {title:'投产数量',field:'amount',align:'center'},
            {title:'合格数量',field:'testedAmount',align:'center',
                formatter:function (value,row,index) {
                    if (value!=null && value!=''){
                        return "<font color='green'>"+value+"</font>";
                    }else{
                        return "<font color='red'>生产中</font>";
                    }
                }
            },
            {title:'派工单状态',field:'checkTag',align:'center',
                formatter:function (value,row,index) {
                    if (value=='1' && row.manufactureProcedureTag=='2'){
                        return "<font color='green'>已完工</font>";
                    }else{
                        return "<font color='red'>执行中</font>";
                    }
                }},
            {title:'生产状态',field:'manufactureProcedureTag',align:'center',
                formatter:function (value,row,index) {
                    if (value=='2'){
                        return "<font color='green'>已完工</font>";
                    }else{
                        return "<font color='red'>执行中</font>";
                    }
                }},
            {title:'查看详情',field:'id',align:'center',
                formatter:function (value,row,index) {
                    let btn="<button class='btn btn-info' onclick='watchManufacture("+JSON.stringify(row)+")'>查看</button>";
                    return btn;
                }
            },
        ]
    })

})

//点击查看
function watchManufacture(row){
    //进入单页
    $(".div1").hide();
    $(".div2").show();
    $("#register").html("");
    $("#productId").html('');
    $("#productName").html("");
    $("#productDescribe").html("");
    $("#amount").html("");
    $("#testedAmount").html("");
    $("#remark").html("");
    $("#checkTime").html("");
    $("#registerTime").html("");
    $("#realModuleCostPriceSum").html("");
    $("#moduleCostPriceSum").html("");
    $("#checker").html('');
    $("#realLabourCostPriceSum").html("");
    $("#labourCostPriceSum").html("");
    $("#manufactureId").html(row.manufactureId);
    $("#status").html(row.manufactureProcedureTag=='2'?"已完工":"执行中")
    //查询产品数量和信息
    $.ajax({
        url:"/DHMManufacture/byId/"+row.id,
        type:"get",
        dataType:"json",
        success:function (date){
            $("#register").html(date.register);
            $("#productId").html(date.productId);
            $("#productName").html(date.productName);
            $("#productDescribe").html(date.productDescribe);
            $("#amount").html(date.amount);
            $("#remark").html(date.remark);
            $("#checkTime").html(date.checkTime);
            $("#registerTime").html(date.registerTime);
            $("#realModuleCostPriceSum").html(date.realModuleCostPriceSum);
            $("#moduleCostPriceSum").html(date.moduleCostPriceSum);
            $("#checker").html(date.checker);
            $("#realLabourCostPriceSum").html(date.realLabourCostPriceSum);
            $("#labourCostPriceSum").html(date.labourCostPriceSum);
            $("#designer").html(date.designer);
            $("#testedAmount").html(date.testedAmount==null?"生产中":date.testedAmount);
            let data=date.mProcedures;
            let tr="";
            for (let i = 0; i < data.length; i++) {
                tr+="<tr>\n" +
                    "<td>"+data[i].detailsNumber+"</td>\n";

                tr+="<td style='color: green;'>";
                if (data[i].procedureFinishTag=='0'){
                    tr+="执行";
                }else if (data[i].procedureFinishTag=='1'){
                    tr+="完成";
                }else if (data[i].procedureFinishTag=='2'){
                    tr+="未完成";
                }else if (data[i].procedureFinishTag=='3'){
                    tr+="执行";
                }
                tr+="</td>";
                tr+="<td>"+data[i].procedureName+"</td>\n" +
                    "<td>"+data[i].subtotal+"</td>\n" +
                    "<td>"+data[i].realSubtotal+"</td>\n" +
                    "<td>"+data[i].moduleSubtotal+"</td>\n" +
                    "<td>"+data[i].realModuleSubtotal+"</td>\n"+
                    "<td></td>";

                tr+= "</tr>";
            }
            $("#tbodyForTr").html(tr);

        }
    })
}

//返回列表
function returnList(){
    $(".div1").show();
    $(".div2").hide();
}

//点击查询
function queryLike(){
    $("#sccxTable").bootstrapTable("refresh");
}